<?php

namespace App\Http\Controllers\Category;

use App\Http\Controllers\Controller;
use App\Models\Category;
use Illuminate\Http\Request;


class CategoryController extends Controller
{
    /**
     * 创建博客类型
     * @param Request $request
     * @return mixed
     */
     public function create(Request $request)
    {
        $type = $request->get('type');
        if ($type) {
            if(!Category::where('type', $type)->first()) {
                Category::create([
                    'type' => $type
                ]);
                return $this->success('创建成功', null);
            }
            return $this->unValidate('博客类型已存在');
        }
        return $this->unValidate('博客类型未填写');
    }

    /**
     * 获取博客类型列表
     */
    public function list()
    {
        $list = Category::get();
        return $this->success('获取成功', $list);
    }

    public function delete(Request $request) {
        Category::where('id', $request->get('id'))->delete();
        return $this->success('删除成功', null);
    }
}
